<?php
class ProjectSelectedSteps extends CActiveRecord {
	/**
	 * The followings are the available columns in table 'v_project_step_tree':
	 * @var string $id
	 * @var string $label
	 * @var string $description
	 * @var integer $project_id
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className = __CLASS__) {
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return 'v_project_step_tree';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		return array (
			array (
				'label',
				'length',
				'max' => 100
			),
			array (
				'id, label, project_id',
				'required'
			),
			array (
				'project_id',
				'numerical',
				'integerOnly' => true
			),

		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations() {
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array (
			'topics' => array (
				self::HAS_MANY,
				'ProjectSelectedTopics',
				'step_id,project_id',
				'order' => 'orderIndex desc',
				'condition' => 'parent_id is null'
			),

		);
	}

	public function primaryKey() {
		return array (
			'id',
			'project_id'
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array (
			'id' => 'Id',
			'label' => 'Label',
			'description' => 'Description',
			'project_id' => 'Project',

		);
	}

	public function canBeObjective(){
		foreach ($this->topics as $topic){
			if ($topic->canBeObjective())
				return true;
		}

		return false;
	}
}